/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package planner_exercise;

import java.util.ArrayList;

/**
 *
 * @author Propietario
 */
public class Operators {
    String obj1;
    String obj2;
    String name;
    int MaxNumRails=3;
    //String types[] = {"COUPLE","PARK","DETACH","ATTACH","LOAD","UNLOAD"};
    String type;
    ArrayList<Predicates> pre;
    ArrayList<Predicates> del;
    ArrayList<Predicates> add;
    public Operators(int totalNumUsedRails,String type,String obj1,String obj2){
        this.pre=new ArrayList<>();
        this.del=new ArrayList<>();
        this.add=new ArrayList<>();
        this.type=type;
        this.obj1=obj1;
        this.obj2=obj2;
        this.name="";
        switch(type){
            case "COUPLE":
                //Preconditions
                if(totalNumUsedRails>1){                                 
                    pre.add(new Predicates("ON-STATION",obj1));
                    pre.add(new Predicates("FREE-LOCOMOTIVE"));
                    pre.add(new Predicates("FREE",obj1));  
                    pre.add(new Predicates("USED-RAILWAYS",totalNumUsedRails));   
                }
 
                //Delete list
                del.add(new Predicates("ON-STATION",obj1));
                del.add(new Predicates("FREE-LOCOMOTIVE"));
                del.add(new Predicates("USED-RAILWAYS",totalNumUsedRails));
                
                //Add list
                add.add(new Predicates("TOWED",obj1));
                add.add(new Predicates("USED-RAILWAYS",totalNumUsedRails-1));
                this.name=type+"("+obj1+")";
                break;
            case "PARK":
                //Preconditions
                if(totalNumUsedRails<MaxNumRails){
                    pre.add(new Predicates("USED-RAILWAYS",totalNumUsedRails));
                    pre.add(new Predicates("TOWED",obj1));
                }
                
                //Delete list
                del.add(new Predicates("TOWED",obj1)); 
                del.add(new Predicates("USED-RAILWAYS",totalNumUsedRails));
                
                //Add list
                add.add(new Predicates("ON-STATION",obj1));
                add.add(new Predicates("FREE-LOCOMOTIVE"));
                add.add(new Predicates("USED-RAILWAYS",totalNumUsedRails+1));
                this.name=type+"("+obj1+")";
                break;
            case "DETACH":
                //Preconditions
                pre.add(new Predicates("IN-FRONT-OF",obj1,obj2));
                pre.add(new Predicates("FREE",obj1));
                pre.add(new Predicates("FREE-LOCOMOTIVE"));
                
                //Delete list
                del.add(new Predicates("IN-FRONT-OF",obj1,obj2));
                del.add(new Predicates("FREE-LOCOMOTIVE"));
                
                //Add list
                add.add(new Predicates("TOWED",obj1));
                add.add(new Predicates("FREE",obj2));
                this.name=type+"("+obj1+")";
                break;
            case "ATTACH":
                //Preconditions
                pre.add(new Predicates("TOWED",obj1));
                pre.add(new Predicates("FREE",obj2));
                
                //Delete list
                del.add(new Predicates("TOWED",obj1));
                del.add(new Predicates("FREE",obj2));
                
                //Add list
                add.add(new Predicates("IN-FRONT-OF",obj1,obj2));
                add.add(new Predicates("FREE-LOCOMOTIVE"));
                this.name=type+"("+obj1+","+obj2+")";
                break;
            case "LOAD":
                //Preconditions
                pre.add(new Predicates("ON-STATION",obj1));
                pre.add(new Predicates("EMPTY",obj1));
                
                //Delete list
                del.add(new Predicates("EMPTY",obj1));
                
                //Add list
                add.add(new Predicates("LOADED",obj1));
                this.name=type+"("+obj1+")";
                break;
            case "UNLOAD":
                //Preconditions
                pre.add(new Predicates("ON-STATION",obj1));
                pre.add(new Predicates("LOADED",obj1));
                
                //Delete list
                del.add(new Predicates("LOADED",obj1));
                
                //Add list
                add.add(new Predicates("EMPTY",obj1));
                this.name=type+"("+obj1+")";
                break;
        }       
    }
    public String nameOperator(String type,String obj1,String obj2){

        if(obj2==null){            
            name= type+"("+obj1+")";
        }
        else{
            name= type+"("+obj1+","+obj2+")";
        }

        return name;
    }
}
